﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.11f1
 *Date:           2019-04-07
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using UnityEngine;

namespace IFramework
{
    public class ABAsyncBundle : ABBundle
    {
        private AssetBundleCreateRequest request;
        public override AssetBundle AB
        {
            get
            {
                if (Err != null) return null;
                return request.assetBundle;
            }
        }
        public override bool IsDone
        {
            get
            {
                if (Err != null) return true;
                return request.isDone;
            }
        }
        public ABAsyncBundle(string url, Hash128 hash) : base(url, hash) { }
        protected override void OnLoad()
        {
            request = AssetBundle.LoadFromFileAsync(Path);
            if (request == null)
                Err = Path + " LoadFromFileAsync falied.";
        }
        protected override void OnUnLoad()
        {
            if (request == null) return;
            if (request.assetBundle != null)
            {
                request.assetBundle.Unload(true);
            }
            request = null;
        }
        public override float Progress
        {
            get { return request.progress; }
        }
    }
}
